package sort;

import java.util.Arrays;

public class SelectSort {

  public static void main(String[] args) {
    int[] arr={5,3,0,89,43,1};
    selectSort(arr);
    System.out.println(Arrays.toString(arr));
  }


  public static void selectSort(int [] arr){

    for (int i = 0; i < arr.length-1; i++) {

        int min=arr[i];
        int minIndex=i;
        for (int j=i+1;j<arr.length;j++){
            if (min>arr[j]){
                min=arr[j];
                minIndex=j;
            }
        }
        if (minIndex!=i){
            arr[minIndex]=arr[i];
            arr[i]=min;
        }

    }
  }
}
